;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Report.DeliverRevokeReport", [])
        .controller("DeliverRevokeReportCtrl", ["$scope", "ybWidget", "ybHttp", "MESG_TYPE", "$filter", "$timeout", function ($scope, ybWidget, ybHttp, MESG_TYPE, $filter, $timeout) {
            $scope.pageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };

            $scope.toolbarConfig = {};

            $scope.tbConf = {
                scrollWidth: 1000,
                tableCol: [
                    {
                        name: "单据号",
                        dataField: "billNo",
                        width: 150,
                    },
                    {
                        name: "零件编号",
                        dataField: "materialsNo",
                        width: 150,
                    },
                    {
                        name: "数量",
                        dataField: "num",
                        width: 120,
                    },
                    {
                        name: "撤回人",
                        dataField: "operateName",
                        width: 120,
                    },
                    {
                        name: "撤回时间",
                        dataField: "operateDateShow",
                        width: 140,
                    }
                ]
            };

            $scope.exportParam = {
                sectionUrl: ybHttp.RequestUrl("device", "/report/deliverRevokeRecordExport"),
            };

            $scope.condition = {};
            $scope.dataList = [];

            $scope.switchToolbar = function (toolbar) {
                if (!!$scope.toolbarConfig["show" + toolbar]) {
                    $scope.toolbarConfig["show" + toolbar] = false;
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig["show" + toolbar] = true;
                    });
                }
            };

            $scope.reset = function () {
                $scope.condition = {};
            };

            // 获取报表列表
            $scope.searchData = function (curPage) {
                var url = '/report/deliverRevokeRecord';
                if (curPage) $scope.pageInfo.curPage = curPage;
                var params = {
                    filters: angular.copy($scope.condition),
                    pageSize: $scope.pageInfo.pageSize,
                    pageNum: $scope.pageInfo.curPage
                };
                ybHttp.Post('device', url, params).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }

                    angular.forEach(resp.value.list, function (item) {
                        item.operateDateShow = $filter("YbDate")(item.operateDate, 'yyyy-MM-dd HH:mm:ss');
                    });

                    $scope.pageInfo.totalRows = resp.value.total;
                    $scope.pageInfo.totalPages = resp.value.pages;
                    $scope.dataList = resp.value.list;
                })
            };

            (function () {
                $scope.searchData();
            })()
        }])
    ;
})(window, window.angular);